/**
 * Coryright 2015-2020 www.eyaomall.cn
 * All rights reserved.
 * @author huwenqing
 * @date 2016年8月3日
 *
 */
package com.eyaomall.wxmanage.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.eyaomall.wxmanage.common.helper.UserHelper;
import com.eyaomall.wxmanage.dao.UserDao;
import com.eyaomall.wxmanage.model.po.User;
import com.eyaomall.wxmanage.service.UserService;
import com.lycheeframework.core.cmp.kit.PageHTTPObject;

@Service
public class UserServiceImpl implements UserService {
	
	@Autowired
	private UserDao userDao;
	
	/**
	 * 验证用户登录
	 */
	public User findUserByAccountAndPasswd(String account, String loginPwd) {
		User user = new User();
		user.setAccount(account);
		user.setPasswd(loginPwd);
		return (User) userDao.query(user);
	}

	/**
	 * 分页查询用户分页信息
	 */
	public Object pageUser(User user, PageHTTPObject object) {
		return userDao.page(user, object);
	}

	/**
	 * 根据userId获取用户信息
	 * @param id
	 * @return
	 */
	public User queryById(Integer id) {
		User user = new User();
		user.setId(id);
		return (User) userDao.query(user);
	}

	/**
	 * 新增用户
	 */
	public boolean createUser(User user) {
		user.setPasswd(UserHelper.getEntryPasswd(user.getPasswd()));
		userDao.insert(user);
		return true;
	}

	/**
	 * 删除
	 */
	public boolean delById(Integer id) {
		User user = new User();
		user.setId(id);
		user.setIsDeleted("y");
		return userDao.update(user)>0?true:false;
	}

	/**
	 * 重置密码
	 */
	public boolean updateUser(User user) {
		user.setPasswd(UserHelper.getEntryPasswd(user.getPasswd()));
		userDao.update(user);
		return true;
	}

	/**
	 * 根据账号查询用户是否存在
	 */
	public User queryByAccount(String account) {
		User user = new User();
		user.setAccount(account);
		return (User) userDao.query(user);
	}

	/**
	 * 根据电话号码查询用户是否存在
	 */
	public User queryByPhone(String phone) {
		User user = new User();
		user.setPhone(phone);
		return (User) userDao.query(user);
	}

}
